﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

//@author A0085749L
namespace EZXPNS
{
    static class Payment
    {
        //To store credit account information
        private static decimal _credit;
        
        //To store debit account information
        private static decimal _debit;

        //To store cash account information
        private static decimal _cash;

        //To store ezlink account information
        private static decimal _ezlink;

        //To store others account information
        private static decimal _others;

        //Constructor
        static Payment()
        {
            _credit = 0m;
            _debit = 0m;
            _cash = 0m;
            _ezlink = 0m;
            _others = 0m;
        }

        //Property for _credit
        public static decimal Credit
        {
            get { return _credit; }
            set { _credit = value; }
        }

        //Property for _debit
        public static decimal Debit
        {
            get { return _debit; }
            set { _debit = value; }
        }

        //Property for _cash
        public static decimal Cash
        {
            get { return _cash; }
            set { _cash = value; }
        }
        
        //Property for _ezlink
        public static decimal Ezlink
        {
            get { return _ezlink; }
            set { _ezlink = value; }
        }

        //Property for _others
        public static decimal Others
        {
            get { return _others; }
            set { _others = value; }
        }

        //Transferring an amount from one account to another 
        //Preconditions: All account names are input in capital letters: CREDIT, DEBIT, CASH, EZLINK, OTHERS
        public static void transfer(string from, string to, decimal amount)
        {
            switch (from)
            {
                case "Credit":
                    Credit -= amount;
                    break;
                case "Debit":
                    Debit -= amount;
                    break;
                case "Cash":
                    Cash -= amount;
                    break;
                case "Ezlink":
                    Ezlink -= amount;
                    break;
                case "Others":
                    Others -= amount;
                    break;
            }

            switch (to)
            {
                case "Credit":                  
                    Credit += amount;
                    break;
                case "Debit":
                    Debit += amount;
                    break;
                case "Cash":
                    Cash += amount;
                    break;
                case "Ezlink":
                    Ezlink += amount;
                    break;
                case "Others":
                    Others += amount;
                    break;
            }
        }

        //Write working memory data to data storage-Payment.txt file
        public static void UpdatePayment()
        {
            StreamWriter outputfile;
            outputfile = File.CreateText("../../Payment.txt");

            outputfile.WriteLine(Credit);
            outputfile.WriteLine(Debit);
            outputfile.WriteLine(Cash);
            outputfile.WriteLine(Ezlink);
            outputfile.WriteLine(Others);

            outputfile.Close();
        }
    }
}
